<?php

namespace Sharks\Core\Http\View;

use Sharks\Core\Http\Response;
use Sharks\Core\Support\Base\Argument;

/**
 * 转向某个网址
 * @package Sharks\Core\Http\Render
 */
class RedirectView extends View {
    private $url;

    public function __construct($url, array $params = [], $hashtag = null) {
        $this->url = $url;
        if (!empty($params)) {
            $this->url .= '?' . http_build_query($params);
        }

        if (!empty($hashtag)) {
            $this->url .= '#' . $hashtag;
        }
    }

    public function render(Response $response) {
        $response->status(303);
        $response->setHeader('Location', $this->url);
    }
}